﻿/**
 * DynaInterpolator3D
 * 
 * @author		Allen Chou
 * @version		1.0.0 (last update: Apr 7 2009)
 * @link        http://cjcat.blogspot.com
 * @link		http://cjcat2266.deviantart.com
 */

package idv.cjcat.utils {
	import flash.display.*;
	
	/**
	 * Almost the same as the <code>DynaInterpolator</code> class, only that it accepts objects with an extra <code>z</code> property defined.
	 * Thus, this interpolator is three-dimensional.
	 */
	public class DynaInterpolator3D extends DynaInterpolator {
		
		public function DynaInterpolator3D(objs:Array = null) {
			super(objs);
			_mi.dimension = 3;
		}
		
		public override function update():void {
			_mi.clear();
			for each (var obj:* in _objs) {
				_mi.push(obj.x, obj.y, obj.z);
			}
		}
		
		public override function interpolate(t:Number, usePercentage:Boolean = false):Object {
			if (_objs.length == 0) return null;
			
			var v3:Vector.<Number> = _mi.interpolate(t, usePercentage);
			return {x:v3[0], y:v3[1], z:v3[2]};
		}
	}
}